package com.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.hibernate.SessionFactory;
import org.hibernate.query.Query;
import org.springframework.stereotype.Repository;

import com.dao.CommentDao;
import com.entity.Comment;
@Repository
public class CommetImpl implements CommentDao {

	@Resource
	private SessionFactory sf;
	public int getSum(){
		String hql="from Comment";
		List<Comment> list=this.sf.getCurrentSession().createQuery(hql).list();
		int sum=list.size()/4;
		if(list.size()%4!=0){
			sum=sum+1;
		}
		return sum;
	}
	public List<Comment> getComment(int page){
		String hql="from Comment";
		Query query = this.sf.getCurrentSession().createQuery(hql);
		query.setFirstResult((page-1)*4);
		query.setMaxResults(4);
		List<Comment> list=query.list();
		return list;
	}
	@Override
	public void addComment(Comment comment) {
		this.sf.getCurrentSession().save(comment);
		
	}
}
